package com.hsnn.medstgmini.pro.project.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hsnn.medstgmini.pro.project.dao.BidScoreRuleDao;
import com.hsnn.medstgmini.pro.project.model.form.BidScoreRuleForm;
import com.hsnn.medstgmini.pro.project.service.BidScoreRuleManager;
import com.hsnn.medstgmini.util.ConstantsUtil;
import com.hsnn.medstgmini.util.Pagination;
import com.hsnn.medstgmini.util.ParseNumber;
@Service
public class BidScoreRuleManagerImpl implements BidScoreRuleManager {
	@Autowired
	private BidScoreRuleDao dao;

	/**
	 * 
	 *@category 获取项目企业资质的评标设置信息
	 *@author 邱磊
	 *@date 2015年9月8日 上午10:36:35
	 *@return
	 */
	public List<BidScoreRuleForm> getCompScoreSet(String projId){
		List<Map<String, Object>> list = dao.getCompScoreSet(projId);
		List<BidScoreRuleForm> fatherList = new ArrayList<BidScoreRuleForm>();
		List<BidScoreRuleForm> childList = null;
		BidScoreRuleForm form = null;
		BidScoreRuleForm childForm = null;
		if (null != list && list.size() > 0){
			String group = "";
			for (int i = 0; i < list.size(); i++){
				Map<String, Object> map = list.get(i);
				childForm = new BidScoreRuleForm();
				if (!group.equals(map.get("scoreGroup").toString())){
					group = map.get("scoreGroup").toString();
					if (null != childList && childList.size() > 0){
						form.setList(childList);
						fatherList.add(form);
					}
					
					form = new BidScoreRuleForm();
					childList = new ArrayList<BidScoreRuleForm>();
				}
				childForm.setScoreObject(3);
				childForm.setScorType(2);
				childForm.setBidScoreRuleId(map.get("isCheck")==null?"":map.get("isCheck").toString());
				childForm.setCheckStatus(map.get("isCheck")==null?0:map.get("isCheck").toString().equals("")?0:1);
				childForm.setDicEntProfileId(map.get("dicEntProfileId")==null?"":map.get("dicEntProfileId").toString());
				if (null != map.get("firstLevelIndiName")){
					childForm.setFirstLevelIndiName(map.get("firstLevelIndiName").toString());
				}
				childForm.setFirstLevelIndiName(map.get("firstLevelIndiName")==null?"":map.get("firstLevelIndiName").toString());
				childForm.setScore(map.get("score")==null?null:ParseNumber.toInteger(map.get("score").toString()));
				childList.add(childForm);
			}
			form.setList(childList);
			fatherList.add(form);
			fatherList.remove(null);
		}
		return fatherList;
	}
	/**
	 * 
	 *@category 获取项目药品资质的评标设置信息
	 *@author 邱磊
	 *@date 2015年9月8日 上午10:36:35
	 *@return
	 */
	public List<BidScoreRuleForm> getDrugScoreSet(String projId){
		List<Map<String, Object>> list = dao.getDrugScoreSet(projId);
		List<BidScoreRuleForm> fatherList = new ArrayList<BidScoreRuleForm>();
		List<BidScoreRuleForm> childList = null;
		BidScoreRuleForm form = null;
		BidScoreRuleForm childForm = null;
		if (null != list && list.size() > 0){
			String group = "";
			for (int i = 0; i < list.size(); i++){
				Map<String, Object> map = list.get(i);
				childForm = new BidScoreRuleForm();
				if (!group.equals(map.get("scoreGroup").toString())){
					group = map.get("scoreGroup").toString();
					if (null != childList && childList.size() > 0){
						form.setList(childList);
						fatherList.add(form);
					}
					form = new BidScoreRuleForm();
					childList = new ArrayList<BidScoreRuleForm>();
				}
				childForm.setScoreObject(3);
				childForm.setScorType(2);
				childForm.setBidScoreRuleId(map.get("isCheck")==null?"":map.get("isCheck").toString());
				childForm.setCheckStatus(map.get("isCheck")==null?0:map.get("isCheck").toString().equals("")?0:1);
				childForm.setDicEntprodProfileId(map.get("dicEntprodProfileId")==null?"":map.get("dicEntprodProfileId").toString());
				if (null != map.get("firstLevelIndiName")){
					childForm.setFirstLevelIndiName(map.get("firstLevelIndiName").toString());
				}
				childForm.setFirstLevelIndiName(map.get("firstLevelIndiName")==null?"":map.get("firstLevelIndiName").toString());
				childForm.setScore(map.get("score")==null?null:ParseNumber.toInteger(map.get("score").toString()));
				childList.add(childForm);
			}
			form.setList(childList);
			fatherList.add(form);
			fatherList.remove(null);
		}
		return fatherList;
	}
	/**
	 * 
	 *@category 获取项目主观分的评标设置信息
	 *@author 邱磊
	 *@date 2015年9月8日 上午10:36:35
	 *@return
	 */
	public List<BidScoreRuleForm> getSubjectScoreSet(String projId){
		List<Map<String, Object>> list = dao.getSubjectScoreSet(projId);
		List<BidScoreRuleForm> fatherList = new ArrayList<BidScoreRuleForm>();
		List<BidScoreRuleForm> childList = null;
		BidScoreRuleForm form = null;
		BidScoreRuleForm childForm = null;
		if (null != list && list.size() > 0){
			String group = "";
			for (int i = 0; i < list.size(); i++){
				Map<String, Object> map = list.get(i);
				childForm = new BidScoreRuleForm();
				if (!group.equals(map.get("scoreGroup").toString())){
					group = map.get("scoreGroup").toString();
					if (null != childList && childList.size() > 0){
						form.setList(childList);
						fatherList.add(form);
					}
					form = new BidScoreRuleForm();
					childList = new ArrayList<BidScoreRuleForm>();
				}
				childForm.setScoreObject(3);
				childForm.setScorType(2);
				childForm.setBidScoreRuleId(map.get("isCheck")==null?"":map.get("isCheck").toString());
				childForm.setCheckStatus(map.get("isCheck")==null?0:map.get("isCheck").toString().equals("")?0:1);
				childForm.setDicSubjectScoreId(map.get("dicSubjectScoreId")==null?"":map.get("dicSubjectScoreId").toString());
				if (null != map.get("subjectScoreName")){
					childForm.setSubjectScoreName(map.get("subjectScoreName").toString());
				}
				childForm.setSubjectScoreName(map.get("subjectScoreName")==null?"":map.get("subjectScoreName").toString());
				childForm.setScore(map.get("score")==null?null:ParseNumber.toInteger(map.get("score").toString()));
				childForm.setFatherName(map.get("fatherName")==null?"":map.get("fatherName").toString());
				childList.add(childForm);
			}
			form.setList(childList);
			fatherList.add(form);
			fatherList.remove(null);
		}
		return fatherList;
	}
	/**
	 * 
	 *@category 设置企业资质评分指标
	 *@author 邱磊
	 *@date 2015年9月8日 下午4:28:44
	 *@param page
	 *@return
	 */
	public void setCompScoreRule(Pagination page){
		dao.setCompScoreRule(page);
	}
	/**
	 * 
	 *@category 获取评分结果
	 *@author 邱磊
	 *@date 2015年9月8日 下午7:44:22
	 *@param page
	 *@return
	 */
	public Pagination getScreResultDataList(Pagination page){
		return dao.getScreResultDataList(page);
	}
	/**
	 * 
	 *@category 获取得分详情
	 *@author 邱磊
	 *@date 2015年9月9日 上午10:21:54
	 *@return
	 */
	public Pagination getScoreResultDetail(Pagination page){
		return dao.getScoreResultDetail(page);
	}
	/**
	 * 
	 *@category 获取报价解密数据列表
	 *@author 邱磊
	 *@date 2015年9月9日 下午1:20:28
	 *@return
	 */
	@SuppressWarnings("unchecked")
	public Pagination getViewDrugPriceList(Pagination page){
		page = dao.getViewDrugPriceList(page);
		List<Map<String, Object>> list = (List<Map<String, Object>>) page.getRows();
		if (null != list && list.size() > 0){
			for (int i = 0; i < list.size(); i++){
				Map<String, Object> map = list.get(i);
				if (null != map.get("decryptStatus")){
					if (0 == ParseNumber.toInteger(map.get("decryptStatus").toString())){
						map.put("decryptPrice", ConstantsUtil.decryptStatus(map.get("decryptStatus").toString()));
					}
					else if (1 == ParseNumber.toInteger(map.get("decryptStatus").toString())){
						map.put("decryptPrice", ConstantsUtil.decryptStatus(map.get("decryptStatus").toString()));
					}
					else if (2 == ParseNumber.toInteger(map.get("decryptStatus").toString())){
						map.put("decryptPrice", ParseNumber.toStrDecimal(ParseNumber.toDouble(map.get("decryptPrice").toString())));
					}
				}
			}
		}
		return page;
	}
	
	/**
	 * 
	 *@category 解密企业
	 *@author wangbing
	 *@date 2015年9月9日 上午10:21:54
	 *@return
	 */
	@Override
	public Pagination getDecryptCompList(Pagination page){
		return dao.getDecryptCompList(page);
	}
	
	/**
	 * 
	 *@category 解密药品
	 *@author wangbing
	 *@date 2015年9月9日 上午10:21:54
	 *@return
	 */
	@Override
	public Pagination getDecryptDrugList(Pagination page){
		return dao.getDecryptDrugList(page);
	}
}
